import { getWechat, getWxAuthor } from '../wechat'
const client = getWechat()
const author = getWxAuthor()
async function getSignature(url) {
  const ticketData = await client.fetchTicket()
  const ticket = ticketData.ticket
  let args = client.sign(ticket, url)
  args.appID = client.appID
  return args
}
function toAuthorizeUrl(...args) {
  return author.toAuthorizeUrl(...args)
}
async function getUserByCode(code) {
  const accessRes = await author.fetchAccessToken(code)
  const user = await author.getUserInfo(accessRes.access_token, accessRes.openid)
  return user
}
export default {
  getSignature,
  toAuthorizeUrl,
  getUserByCode
}
